<template>
  <div>
    <div class="gray_tip">
      <p>共为您找到约{{ totalRow }}篇相关结果</p>
    </div>
    <ul class="content">
      <li
        v-for="(item, index) of currentPageData"
        :key="index"
        @click="todetail(item.id, item.quanjing)"
      >
        <img :src="IP + currentPageData[index].thumb" alt />
        <div class="right_content">
          <p class="content_title">{{ currentPageData[index].name }}</p>
          <span>{{ currentPageData[index].title }}</span>
        </div>
      </li>
    </ul>
    <div id="page">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :pager-count="5"
        :page-size="pageSize"
        layout="prev, pager, next"
        :total="this.totalPage"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  props: [
    "currentPageData",
    "searchdetail_content",
    "navIdx",
    "navSelectData",
    "sort",
    "choose_agree",
    "content",
  ],
  data() {
    return {
      productList: [{}], //所有数据
      totalPage: 0,
      currentPage: 1, //当前页数 ，默认为1
      pageSize: 5, // 每页显示数量
      currentPageData: [],
      totalRow: 0, //长度
    };
  },
  methods: {
    // 全部的搜搜接口
    allsearch() {
      this.$api
        .get(
          `${this.book}seach/${this.props.sort}?pageNumber=${this.currentPage}&pageSize=${this.pageSize}&catid=${this.props.choose_agree}&keyword=${this.props.content}`
        )

        .then((res) => {
          console.log(this.res, "all");
          // this.totalPage = res.data.paginate.totalPage;
          // this.totalRow = res.data.paginate.totalRow;
          this.currentPageData = res.data;
        });
    },
    setCurrentPageData() {
      if (this.sort == "seachAll") {
        this.allsearch();
        return;
      }
      this.$api
        .get(
          `${this.book}seach/${this.props.sort}?pageNumber=${this.currentPage}&pageSize=${this.pageSize}&catid=${this.props.choose_agree}&keyword=${this.props.content}`
        )

        .then((res) => {
          console.log(res, "detail");
          this.totalPage = res.data.paginate.totalPage;
          this.totalRow = res.data.paginate.totalRow;
          this.currentPageData = res.data.paginate.list;
        });
    },
    handleCurrentChange(val) {
      if (val != this.currentPage) {
        this.currentPage = val;
      }

      // this.page = val;
      this.setCurrentPageData(
        `${this.book}seach/${this.sort}?pageNumber=${this.currentPage}pageSize=${this.pageSize}&catid=${this.choose_agree}&keyword=${this.content}`
      );
    },

    todetail(id, quanjing) {
      if (this.choose_agree == 24) {
        this.$router
          .push({
            path: `/guanwugongkai/consultdetail?id=${id}`,
            query: { orderId: 1 },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 25) {
        this.$router
          .push({
            path: `/guanwugongkai/huodonggonggaodetail?id=${id}`,
            query: { orderId: 2 },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 26) {
        this.$router
          .push({
            path: `/guanwugongkai/guanwugongkai2detail?id=${id}`,
            query: { orderId: 3 },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 45) {
        this.$router
          .push({
            path: `/guanwugongkai/wenbodongtaidetail?id=${id}`,
            query: { orderId: 4 },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 57) {
        this.$router
          .push({
            path: `/guanwugongkai/dashijidetail?id=${id}`,
            query: { orderId: 5 },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 55) {
        this.$router
          .push({
            path: `/linzhan/line/year1detail?id=${id}`,
            query: { orderId: 2, bool: true },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 27) {
        this.$router
          .push({
            path: `/linzhan/basezdetail?id=${id}`,
            query: { orderId: 1, bool: true },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 56) {
        if (quanjing == "") {
          this.$router
            .push({
              path: `/linzhan/yeardetail?id=${id}`,
              query: { orderId: 3, bool: true },
            })
            .catch((err) => {
              err;
            });
        } else {
          let quanjingData = this.$router.resolve({
            name: "quanjing",
            query: { orderId: 3, bool: true, id: id },
          });
          console.log(quanjingData, 11);
          window.open(quanjing, "_blank");
        }
      } else if (this.choose_agree == 33) {
        this.$router
          .push({
            path: `/huodongyugao/huodongyugao2detail?id=${id}`,
            query: {
              orderId: 1,
            },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 34) {
        this.$router
          .push({
            path: `/huodongyugao/wenboketangdetail?id=${id}`,
            query: { orderId: 2, id: id },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 35) {
        this.$router
          .push({
            path: `/huodongyugao/wenbojiangzuodetail?id=${id}`,
            query: {
              orderId: 3,
              balance: this.$store.state.setBalance_jz,
              id: id,
              title: this.$store.state.jz_title,
            },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == 36) {
        this.$router
          .push({
            path: `/huodongyugao/qinshaonianhuodongdetail?id=${id}`,
            query: { orderId: 4, id: id },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == "8a7aef0958b37e280158b38d781e0033") {
        this.$router
          .push({
            path: "/cangpinjiansuo/cangpinjiansuo2/:id",
            query: {
              orderId: 1,

              sort: "8a7aef0958b37e280158b38d781e0033",
            },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == "8a7aef0958b37e280158b38e61b4003b") {
        this.$router
          .push({
            path: "/cangpinjiansuo/cangpinjiansuo2/:id",
            query: {
              orderId: 2,

              sort: "8a7aef0958b37e280158b38e61b4003b",
            },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == "8a7aef0958b37e280158b39114d30057") {
        this.$router
          .push({
            path: "/cangpinjiansuo/cangpinjiansuo2/:id",
            query: {
              orderId: 3,

              sort: "8a7aef0958b37e280158b39114d30057",
            },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == "8a7aef0958b37e280158b391666e005b") {
        this.$router
          .push({
            path: "/cangpinjiansuo/cangpinjiansuo2/:id",
            query: {
              orderId: 4,

              sort: "8a7aef0958b37e280158b391666e005b",
            },
          })
          .catch((err) => {
            err;
          });
      } else if (this.choose_agree == "8a7aef0958b37e280158b38ffed8004b") {
        this.$router
          .push({
            path: "/cangpinjiansuo/cangpinjiansuo2/:id",
            query: {
              orderId: 5,

              sort: "8a7aef0958b37e280158b38ffed8004b",
            },
          })
          .catch((err) => {
            err;
          });
      } else if (
        this.choose_agree == "8a7aef0958b37e280158b391b34d005f" ||
        "4028c2526174389e016182f203ca002c" ||
        "8a7aef0958b37e280158b38ffed8004b" ||
        "8a7aef0958b37e280158b38fabab0047" ||
        "8a7aef0958b37e280158b390a8290053" ||
        "8a7aef0958b37e280158b38f0331003f" ||
        "8a7aef0958b37e280158b3933a730073"
      ) {
        this.$router
          .push({
            path: "/cangpinjiansuo/cangpinjiansuo2/:id",
            query: {
              orderId: 6,

              sort:
                "8a7aef0958b37e280158b391b34d005f" ||
                "4028c2526174389e016182f203ca002c" ||
                "8a7aef0958b37e280158b38ffed8004b" ||
                "8a7aef0958b37e280158b38fabab0047" ||
                "8a7aef0958b37e280158b390a8290053" ||
                "8a7aef0958b37e280158b38f0331003f" ||
                "8a7aef0958b37e280158b3933a730073",
            },
          })
          .catch((err) => {
            err;
          });
      }
    },
  },
};
</script>